package priv.mill.bigdata.autompg;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

public class AutoMpgReducer extends Reducer< IntWritable, MyInfo, IntWritable, MyInfo>{

	@Override
	protected void reduce(IntWritable key, Iterable<MyInfo> infos,
			Reducer<IntWritable, MyInfo, IntWritable, MyInfo>.Context context) throws IOException, InterruptedException {
		Integer horsepower = 0;
		Integer weight=0;
		int count = 0;
		for (MyInfo myInfo : infos) {
			weight += myInfo.getWeight();
			horsepower += myInfo.getHorsepower();
			count++;
		}
		MyInfo myInfo = new MyInfo();
		myInfo.setHorsepower(horsepower/count);
		myInfo.setWeight(weight/count);
		context.write(key, myInfo);
	}

}
